//
//  XFVisitView.m
//  SinaBlog_OC
//
//  Created by macs on 15/11/10.
//  Copyright © 2015年 BlackTail. All rights reserved.
//

#import "XFVisitView.h"


@interface XFVisitView ()

@property(nonatomic, strong) UIImageView *circlrView;
@property(nonatomic, strong) UIImageView *iconView;
@property(nonatomic, strong) UILabel *descriLable;
@property(nonatomic, strong) UIButton *loginBtn;
@property(nonatomic, strong) UIButton *registBtn;
@property(nonatomic, strong) UIImageView *coverView;

@end

@implementation XFVisitView

- (instancetype)init {
  self = [super init];
  if (self) {
    self.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1];
    [self setupUI];
    [self loadSubViewsFrame];
  }
  return self;
}

- (void)setupAnimate {

  CABasicAnimation *anim = [[CABasicAnimation alloc] init];
  anim.keyPath = @"transform.rotation";
  anim.byValue = @(2 * M_PI);
  anim.duration = 20;
  anim.repeatCount = MAXFLOAT;
  anim.removedOnCompletion = NO;
  [self.circlrView.layer addAnimation:anim forKey:nil];
}

- (void)setupSubViewsWithImage:(NSString *)imageName
                    andMessage:(NSString *)message {
  self.iconView.hidden = NO;
  self.descriLable.text = message;
  if (imageName != nil) {
    self.circlrView.image = [UIImage imageNamed:imageName];
    self.iconView.hidden = YES;
    [self bringSubviewToFront:self.circlrView];
  } else {
    [self setupAnimate];
  }
}

- (void)setupUI {
  UIImageView *circleView = [[UIImageView alloc] init];
  circleView.image =
      [UIImage imageNamed:@"visitordiscover_feed_image_smallicon"];
  [self addSubview:circleView];
  self.circlrView = circleView;

  UIImageView *coverView = [[UIImageView alloc] init];
  coverView.image = [UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"];
  [self addSubview:coverView];
  self.coverView = coverView;

  UIImageView *iconView = [[UIImageView alloc] init];
  iconView.image = [UIImage imageNamed:@"visitordiscover_feed_image_house"];
  [self addSubview:iconView];
  self.iconView = iconView;

  UILabel *descriLable = [[UILabel alloc]
      initWithTitle:@"关注一些人，回这里看看有什么惊喜"
              Color:[UIColor lightGrayColor]
               Font:14
             Margin:0];
  [self addSubview:descriLable];
  self.descriLable = descriLable;

  UIButton *loginBtn =
      [[UIButton alloc] initWithTitle:@"登录"
                                Color:[UIColor lightGrayColor]
                               BgIcon:@"common_button_white_disable"
                                Image:nil];
  [loginBtn addTarget:self
                action:@selector(loginClick)
      forControlEvents:UIControlEventTouchUpInside];
  [self addSubview:loginBtn];
  self.loginBtn = loginBtn;

  UIButton *registBtn =
      [[UIButton alloc] initWithTitle:@"注册"
                                Color:[UIColor orangeColor]
                               BgIcon:@"common_button_white_disable"
                                Image:nil];

  [registBtn addTarget:self
                action:@selector(registClick)
      forControlEvents:UIControlEventTouchUpInside];
  [self addSubview:registBtn];
  self.registBtn = registBtn;
}

- (void)loginClick {
  if ([self.visitViewDelegate respondsToSelector:@selector(loginDidClick)]) {
    [self.visitViewDelegate loginDidClick];
  }
}

- (void)registClick {
  if ([self.visitViewDelegate respondsToSelector:@selector(registDidClick)]) {
    [self.visitViewDelegate registDidClick];
  }
}

- (void)loadSubViewsFrame {
  [self.circlrView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerX.equalTo(self.mas_centerX);
    make.centerY.equalTo(self.mas_centerY).offset(-60);
  }];

  [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerX.equalTo(self.circlrView.mas_centerX);
    make.centerY.equalTo(self.circlrView.mas_centerY);
  }];

  [self.descriLable mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.circlrView.mas_bottom);
    make.centerX.equalTo(self.circlrView.mas_centerX);
    make.width.equalTo(@224);
    make.height.equalTo(@40);
  }];

  [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.descriLable.mas_bottom);
    make.left.equalTo(self.descriLable.mas_left);
    make.width.equalTo(@100);
    make.height.equalTo(@35);
  }];
  [self.registBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.descriLable.mas_bottom);
    make.right.equalTo(self.descriLable.mas_right);
    make.width.equalTo(@100);
    make.height.equalTo(@35);
  }];

  [self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.mas_top).offset(60);
    make.left.equalTo(self.mas_left);
    make.right.equalTo(self.mas_right);
    make.bottom.equalTo(self.registBtn.mas_top);
  }];
}

@end
